package com.du.limiting.sentinel.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.du.limiting.sentinel.model.User;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.concurrent.TimeUnit;

/**
 * @author dujunguang
 * @date 2022/2/23 13:52
 * @description: TODO
 **/
@Service
public class SentinelLimitingService {

//    @SentinelResource("hotPoint")
    public User hotPoint(String name) {
        User user = new User();
        user.setName(name);
        user.setAge(100);
        return user;
    }


//    @SentinelResource("flowControlQps")
    public User flowControlQps(String name) {
        User user = new User();
        user.setName(name);
        user.setAge(100);
        return user;
    }

    @SentinelResource("flowControlThreadNum")
    public User flowControlThreadNum(String name) {
        try {
            TimeUnit.MILLISECONDS.sleep(800);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        User user = new User();
        user.setName(name);
        user.setAge(100);
        return user;
    }

    @SentinelResource("flowControlLimitApp")
    public User flowControlLimitApp(String name) {
        User user = new User();
        user.setName(name);
        user.setAge(50);
        return user;
    }

}
